/**
 * @program: 1.15 栈和队列
 * @description:
 * @author: 李鑫月
 * @create: 2022-01-16 21:47
 **/
public class MyCircularQueue {
    public int front;
    public int rear;
    public int length;
    public int[] queue;
    public MyCircularQueue(int k) {
        this.length=k;
        this.queue=new int[length];

    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        queue[rear]=value;
        rear=(rear+1)%length;

        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front=(front+1)%length;
        return true;

    }

    public int Front() {
       if(isEmpty()){
           return -1;
       }
       return queue[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        return queue[(rear-1+length)%length];

    }

    public boolean isEmpty() {
        if(front==rear){
            return true;
        }
        return false;

    }

    public boolean isFull() {
        if((rear+1)%length==front){
            return  true;
        }
        return false;

    }
}
